<% layout('layout/layout') %>
<% block('header').append(`<style>
</style>`) %>
<div class="row">
    <div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">添加导航</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="<%=assetsPath %>/catalog/add" method="post" class="form-horizontal" novalidate>
                <div class="box-body">
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">名称</label>
                        <div class="col-sm-10">
                            <input name="nameCn" value="<%=curr.nameCn || '' %>" type="text" class="form-control"  placeholder="单页标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="path" class="col-sm-2 control-label">路径名称</label>
                        <div class="col-sm-10">
                            <input name="name"  value="<%=curr.name || '' %>" ttype="text" class="form-control" placeholder="显示的url路径">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="parent" class="col-sm-2 control-label">父菜单</label>
                        <div class="col-sm-10">
                            <select name="parent" class="form-control">
                                <% catalogs.forEach(function(item){ %>
                                <option value="<%=item.calPath || '' %>,<%=item.name %>" <%=curr.calPath === item.calPath+','+item.name?'selected':'' %> >
                                    <%=item.deepStr%><%=item.nameCn%>
                                </option>
                                <% }) %>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="path" class="col-sm-2 control-label">关联页面路径</label>
                        <div class="col-sm-10">
                            <input name="relativeUrl"  value="<%=curr.relativeUrl || '' %>" ttype="text" class="form-control" placeholder="关联的Url">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="title" class="col-sm-2 control-label">图片展示</label>
                        <div class="col-sm-10">
                            <a id="imgUpload" class="btn  btn-sm btn-success">图片上传</a>
                            <input id="imgInput" name="imgUrl" type="hidden" value="<%=curr.imgUrl || ''%>">
                            <div id="showImg" class="show_img" style="width:200px;" >
                                <% if (curr.imgUrl){ %>
                                <i class="ionfont "></i>
                                <img src="<%=curr.imgUrl %>" style="max-height:100%;max-width:100%" >
                                <% }%>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="path" class="col-sm-2 control-label">关联模板类别</label>
                        <div class="col-sm-10">
                            <input name="useTpl"  value="<%=curr.useTpl || '' %>" ttype="text" class="form-control" placeholder="相关模板类别（留空）">
                        </div>
                    </div> <div class="form-group">
                        <label for="path" class="col-sm-2 control-label">排序</label>
                        <div class="col-sm-10">
                            <input name="sort"  value="<%=curr.sort || '100' %>" ttype="text" class="form-control" placeholder="排序">
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                        <!--<div class="col-sm-offset-2 col-sm-10">-->
                            <!--<div class="checkbox">-->
                                <!--<label>-->
                                    <!--<input name="isMaster" type="checkbox" value="1"> 是否根路径-->
                                <!--</label>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</div>-->
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <div class="checkbox">
                                <label>
                                    <input name="isValid" <%=curr.isValid?'checked':''%>  value="1" type="checkbox" > 是否有效
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <div class="col-sm-offset-2 col-sm-10">
                        <% if (curr._id) { %>
                        <input name="_id" type="hidden" value="<%=curr._id %>">
                        <% } %>
                        <button type="submit" class="btn btn-info ">保存</button>
                        <button type="reset" class="btn btn-default">重置</button>
                    </div>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>
<% block('footer').append(`<script src="${assetsPath}/js/uploadImg.js"></script>`); %>
<% block('footer').append(`<script>
jQuery(function(){
		function createImg () {
		var img
		return function (url,cb) {
			if (!img) {
                img = new Image()
                img.src = url
                img.style['max-width'] = '100%'
                img.style['max-height'] = '100%'
                img.onload = function () {
                    img.onload = null
                    cb(img)
                }
            } else {
				img.src = url
				img.onload =function () {
					img.onload = null
					cb(img)
				}
            }
		}
	}
	var getImg =  createImg()
	$('#imgUpload').uploadImg(function(imgs){
    	if (imgs && imgs.length > 0) {
            var url = imgs[0].thumb.url
    	    $('#imgInput').val(url)
            getImg(url,function(img){
               $('#showImg').empty().append(img)
            })
    	}
    })
})
</script>`) %>